<?php
    $link = mysql_connect('mysql12.freehostia.com', 'davmor88_aleydei', 'Admin123');
    mysql_select_db('davmor88_aleydei');
    mysql_query("SET NAMES utf8");
    mysql_query("SET CHARACTER SET utf8");
    
    /*$link = mysql_connect('localhost', 'root', 'Admin123');
    mysql_select_db('aleydei');
    mysql_query("SET NAMES utf8");
    mysql_query("SET CHARACTER SET utf8");*/
    
    if(isset($_POST['code'])){
    	$code = $_POST['code'];
	    //$code = $_GET['code'];
	    
	    $qry = "Select * From invitados Where code = $code";
	    $r = mysql_query($qry);
	    $rec = mysql_fetch_assoc($r);
	    mysql_free_result($r);
	}else{
		$rec = false;
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

<link rel="stylesheet" href="../css/styles.css">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script>
    function save(){
        $("#webs").append("<div id=\"waitdiv\" style=\"height: 440px; width: 100%;\" align=\"center\"><div class=\"waitimgs\"></div></div>");
        $.post('./content/invitados/save.php', {'code': '<?php echo $code; ?>', 'cantidad':$('#cantidad').val()}, function(data){
            $('#webs').html(data);
        });
    }
</script>
</head>
<body>
    <div class="hojas" style="height: 420px; width: 100%; repeat;" align="center">
    <?php
    	if($rec == false){ ?>
        <div style="border: 2px outset #FFFFFF; margin-top: 130px; width: 250px; font-family: 'Arial'; font-size: 14px; font-weight: bold; padding-bottom: 15px; padding-top: 10px; background-color: #FFFFFF;
        border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px;">
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td valign="middle" align="center">
                        La clave proporcionada<br/>no es v&aacute;lida<br/>Vuelva a intentarlo:<div style="height:15px;"></div>
                        <input id="code" type="text" class="text" size="20">
                    </td>
                    <td valign="bottom" style="padding-left: 5px;">
                        <img class="continue" src="../img/next.png" onclick="loadinvi();" width="25px" height="25px"/>
                    </td>
                </tr>
            </table>
        </div>
    <?php
        	echo "<script>$('#code').focus();</script>";
	 	}else { ?>
        <div style="height: 95px;"></div>
        <span style="font-family: Arial; font-size: 16px; color: #CCCCCC;"><b>Hola</b> <?php echo $rec['descripcion']; ?></span>
        <div style="height: 8px;"></div>    
        <span style="font-family: Arial; font-size: 12px; color: #999999;">
            Confirma el numero de invitados que nos acompa&ntilde;aran:&nbsp;
            <select id="cantidad" class="text">
                <?php for($i=0;$i<=$rec['cantidad'];$i++){ ?>
                <option value="<?php echo $i; ?>" <?php echo $i == $rec['confirm'] ? "selected" : "" ?>><?php echo $i; ?></option>
                <?php } ?>
            </select>
            <img class="continue" src="../img/next.png" onclick="save();" width="15px" height="15px" style="padding-left: 8px;"/>
        </span>
        
        <?php } ?>
    </div>
</body>
</html>